﻿using AbpToDomain.EntityInfo;
using AbpToDomain.View;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;

namespace AbpEntityFrameworkcore.DbContext
{
    [ConnectionStringName("Lmsconnstr")]
    public class MyDbContext : AbpDbContext<MyDbContext>
    {


        public DbSet<lognote> lognotes { get; set; }
        public DbSet<Position> Positions { get; set; }
        public DbSet<TaskOrder> TaskOrders { get; set; }
        public DbSet<MaterialList> MaterialLists { get; set; }
        public DbSet<TaskInfo> TaskInfos { get; set; }

        public virtual DbSet<View_TaskOrder> View_TaskOrders { get; set; }




        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
        {

      
        }
     

     

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            builder.Entity<lognote>(n =>
            {
                n.ToTable("lognote");
            });

            builder.Entity<TaskInfo>(n =>
            {
                n.ToTable("TaskInfo");
            });

            builder.Entity<Position>(n =>
            {
                n.ToTable("Position");
            });
            builder.Entity<TaskOrder>(n =>
           {
               n.ToTable("TaskOrder");
               n.HasOne<Position>(x => x.Origination)
                .WithMany()
                .HasForeignKey(x => x.Origination_Id)
                .OnDelete(DeleteBehavior.NoAction);

               n.HasOne<Position>(x => x.Target)
                .WithMany()
                .HasForeignKey(x => x.Target_Id)
                .OnDelete(DeleteBehavior.NoAction);

           });

            builder.Entity<MaterialList>(n =>
          {
                            n.ToTable("MaterialList");
            });


            builder.Entity<View_TaskOrder>(n =>
            {
                n.ToTable("View_TaskOrder").HasNoKey();
  
            });

        }

    }
  

}
